package com.sjgs.gis.fsrest.router;

import com.sjgs.gis.fsrest.handler.FileSystemDownloadHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

import org.springframework.context.annotation.Configuration;

@Configuration
public class RouterConfig {

    @Autowired
    private FileSystemDownloadHandler FShander;

    @Bean
    public RouterFunction<ServerResponse> fileSystemRouter() {
        return route(RequestPredicates.GET("/download-service/file/{fkey}").and(RequestPredicates.accept(MediaType.ALL)), FShander::getFile)
                .andRoute(RequestPredicates.GET("/download-service/chunk/{fkey}/index/{index}").and(RequestPredicates.accept(MediaType.ALL)), FShander::getChunk)
                .andRoute(RequestPredicates.GET("/tile-service/{id}").and(RequestPredicates.accept(MediaType.ALL)), FShander::getTileSet)
                .andRoute(RequestPredicates.GET("/tile-service/{id}/**").and(RequestPredicates.accept(MediaType.ALL)), FShander::getTile);
    }

}
